package com.ycsoft.ttctn;

import com.sun.javafx.scene.layout.region.Margins;

import java.io.IOException;
import java.util.Scanner;

public class Main {
    //----------------------------mainmenu 相关内容--------------------------//
    public static void main(String[] args) {
        // 1. 显示第一级菜单. AAAA
        int mainmenu_sel = show_mainmenu();

        while (mainmenu_sel!=0) {
            switch (mainmenu_sel) {
                case 1:
                    process_menu_1();
                    break;
                case 2:
                    process_menu_2();
                    break;
            }
            // 重新显示选择菜单。
            mainmenu_sel = show_mainmenu();
        }
    }

    private static void show_enter(int times) {
        for(int i=0; i < times; i++) {
            System.out.println("");
        }
    }

    private static int show_mainmenu() {
        System.out.println("主菜单");
        System.out.println("---------------------------");
        System.out.println(" 1. Java语言学习测试。    ");
        System.out.println(" 2. 显示自定义函数功能测试。");
        System.out.println("---------------------------");
        System.out.println("0. 退出（Exit）");
        System.out.println("---------------------------");

        show_enter(6);

        System.out.print("请输入你的选择（按回车确认）：");
        Scanner input = new Scanner(System.in);

        return input.nextInt();
    }

    //----------------------------menu1 相关内容--------------------------//
    private static int show_menu_1() {
        System.out.println("主菜单 -> 菜单1");
        System.out.println("---------------------------");
        System.out.println("1. 示例1_1。");
        System.out.println("2. 示例1_2。");
        System.out.println("---------------------------");
        System.out.println("0. 返回上一级");
        System.out.println("---------------------------");

        show_enter(6);

        System.out.print("请输入你的选择（按回车确认）：");
        Scanner input = new Scanner(System.in);

        return input.nextInt();
    }

    private static void process_menu_1() {
        try {
            Runtime.getRuntime().exec("clear");
        } catch (IOException e) {
            //e.printStackTrace();
        }

        int menu_1_sel = show_menu_1();

        while (menu_1_sel!=0) {
            switch (menu_1_sel) {
                case 1:
                    break;
                case 2:
                    break;
            }
            // 重新显示选择菜单。
            menu_1_sel = show_menu_1();
        }
    }

    //----------------------------menu2 相关内容--------------------------//
    private static int show_menu_2() {

        System.out.println("主菜单 -> 菜单2");
        System.out.println("---------------------------");
        System.out.println("1. YcUtils功能测试。");
        System.out.println("2. Memberformat功能测试。");
        System.out.println("---------------------------");
        System.out.println("0. 返回上一级");
        System.out.println("---------------------------");

        show_enter(6);

        System.out.print("请输入你的选择（按回车确认）：");
        Scanner input = new Scanner(System.in);

        return input.nextInt();
    }

    private static void process_menu_2() {
        int menu_2_sel = show_menu_2();

        while (menu_2_sel!=0) {
            switch (menu_2_sel) {
                case 1:
                    do_func_2_1();
                    break;
                case 2:
                    do_func_2_2();
                    break;
            }
            // 重新显示选择菜单。
            menu_2_sel = show_menu_2();
        }
    }
    private static void do_func_2_1() {
        String name = "012345";

        System.out.println("--------name:" + name);
        System.out.println(YcUtils.padLeft(name, 10, '*'));
        System.out.println(YcUtils.padRight(name, 10, '*'));

        name = "0123456789";

        System.out.println("--------name:" + name);
        System.out.println(YcUtils.padLeft(name, 10, '*'));
        System.out.println(YcUtils.padRight(name, 10, '*'));

        name = "0123456789abcdef";

        System.out.println("--------name:" + name);
        System.out.println(YcUtils.padLeft(name, 10, '*'));
        System.out.println(YcUtils.padRight(name, 10, '*'));

        // 陈晖可变参数测试.
        Callme("ChenHui", 1001, true, 32L);
    }

    private static void do_func_2_2() {
        // 测试MemberFormat.
        Double d = 312.5;
        try {
            System.out.println(MemberFormat.getFormatMember("X008_2", d, false));
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            System.out.println(MemberFormat.setFormatMember("X008_2", "00031250"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void Callme(Object...args) {
        for(int i=0; i<args.length; i++) {
            if (args[i] instanceof Integer) {
                int k = (int) args[i];
                System.out.println(String.format("整型：%d", k));
            } else if (args[i] instanceof Long) {
                long l = (long) args[i];
                System.out.println(String.format("长整型：%d", l));
            } else if (args[i] instanceof String) {
                System.out.println(String.format("字符串：%s", args[i].toString()));
            } else if (args[i] instanceof Boolean) {
                System.out.println(String.format("布尔型：%s", args[i].toString()));
            } else {
                System.out.println("未处理的参数类型:" + args[i].toString());
            }

        }
    }
}
